import club.zhilin.guli.service.base.model.BaseDomain;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.fill.Column;
import org.junit.jupiter.api.Test;

import java.util.Collections;

/**
 * @author zhilin
 * @since 2022/1/11 13:18
 */

public class CodeGenerator {

    @Test
    public void test() {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/guli_statistics?useSSL=false&serverTimezone=GMT%2b8", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("zhilin") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .dateType(DateType.ONLY_DATE)
                            .disableOpenDir()
                            .commentDate("yyyy-MM-dd HH:mm:ss")
                            .outputDir("E:\\Workspace\\Java\\guli_parent\\service\\service-statistics\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("club.zhilin.guli.service") // 设置父包名
                            .moduleName("statistics").entity("domain") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\Workspace\\Java\\guli_parent\\service\\service-statistics\\src\\main\\resources\\mappers")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("statistics_daily") // 设置需要生成的表名
                            .addTablePrefix("statistics_")// 设置过滤表前缀
                            .entityBuilder().idType(IdType.ASSIGN_ID).superClass(BaseDomain.class).enableRemoveIsPrefix()
                            .enableLombok().logicDeleteColumnName("is_deleted").enableTableFieldAnnotation().versionColumnName("version").addTableFills(new Column("gmt_create", FieldFill.INSERT), new Column("gmt_modified", FieldFill.INSERT_UPDATE), new Column("is_deleted", FieldFill.INSERT), new Column("version", FieldFill.INSERT)).enableRemoveIsPrefix()
                            .controllerBuilder().enableRestStyle();
                })
                .execute();
    }


}